<template>
    <a-modal
        :title="i18n('form.orgChoice','机构选择')"
        v-bind:visible="visible"
        width="800px"
        :bodyStyle="{height:'480px;'}"
        @ok="handleOk"
        @cancel="handleCancel">

        <rx-layout>
            <div slot="center" style>
                <rx-fit>
                    <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                        <a-row :gutter="24">
                            <a-col :span="8" :style="{display: 'block' }">
                                <a-form-item :label="i18n('form.coding','编码')">
                                    <a-input :placeholder="i18n('form.coding','编码')" v-model="queryParam.Q_INST_NO__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="8" :style="{display: 'block' }">
                                <a-form-item :label="i18n('form.organization','机构名称')">
                                    <a-input :placeholder="i18n('form.organization','机构名称')" v-model="queryParam.Q_NAME_CN__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="8">
                                <a-button type="primary" html-type="submit" @click="handleSearch">
                                    {{$ti18('rxList.searchForBtn','搜索')}}
                                </a-button>
                                <a-button :style="{ marginLeft: '8px' }" @click="handleReset">
                                    {{i18n('form.clearBtn','清空')}}
                                </a-button>
                              </a-col>
                        </a-row>
                    </div>
                    <rx-grid
                        ref="table"
                        :allowRowSelect="true"
                        :multiSelect="false"
                        :columns="columns"
                        :defaultPageSize="10"
                        url="/api-user/user/org/public/getValidInsts"
                        :queryParam="queryParam"
                        data-field="result.data"
                        :pageSizeOptions="['10','30','40']"
                        id-field="instId"
                        @selectChange="onSelectChange"
                    >
                    </rx-grid>
                </rx-fit>
            </div>
        </rx-layout>


    </a-modal>
</template>
<script>
import {BaseList,RxFit,RxGrid,Util} from '@lowcode/jpaas-common-lib';

export default {
    name: "TenantSelectDialog",
    mixins: [BaseList],
    components: {
        RxGrid,
        RxFit
    },
    props:{
        visible:{
            type:Boolean,
            required:true
        },
    },
    data(){
        return {
                queryParam:{},
                columns:[
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 60,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.coding','编码'), dataIndex: 'instNo', width: 100},
                {title: this.i18n('form.organization','机构名称'), dataIndex: 'nameCn', width: 200}
            ],
            fitSearch:true,
        }
    },
    methods:{
        i18n(name, text, key) {
            return this.$ti18(name, text, "viewsUser", key);
        },
        handleSearch(){
            this.$refs.table.loadData();
        },
        handleReset(){
            this.resetSearch();
        },
        handleOk(){
            let selRows=[];
            if(this.selectedRows.length>0){
                selRows=Util.deepClone(this.selectedRows);
            }
            //在这里获取选择的机构
            this.$emit('ok',selRows);
        },
        handleCancel(){
            this.$emit('cancel');
        },
        onSelectChange(selectedRowKeys, selectedRows) {
            this.selectedRowKeys = selectedRowKeys;
            this.selectedRows = selectedRows
        },
    }
}
</script>
<style scoped>
</style>